package org.springxrsk.modules.auth.config;

import org.springxrsk.core.jwt.props.JwtProperties;
import org.springxrsk.core.oauth2.config.OAuth2AutoConfiguration;
import org.springxrsk.core.oauth2.handler.AuthorizationHandler;
import org.springxrsk.core.oauth2.handler.PasswordHandler;
import org.springxrsk.core.oauth2.handler.TokenHandler;
import org.springxrsk.core.oauth2.service.OAuth2ClientService;
import org.springxrsk.core.oauth2.service.OAuth2UserService;
import org.springxrsk.core.redis.cache.XrskRedis;
import org.springxrsk.core.tenant.XrskTenantProperties;
import org.springxrsk.modules.auth.handler.XrskAuthorizationHandler;
import org.springxrsk.modules.auth.handler.XrskPasswordHandler;
import org.springxrsk.modules.auth.handler.XrskTokenHandler;
import org.springxrsk.modules.auth.service.XrskClientDetailService;
import org.springxrsk.modules.auth.service.XrskUserDetailService;
import org.springxrsk.modules.system.service.IUserService;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * XrskAuthConfiguration
 *
 * @author
 */
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore(OAuth2AutoConfiguration.class)
public class XrskAuthConfiguration {
	@Bean
	public AuthorizationHandler authorizationHandler(XrskRedis XrskRedis, XrskTenantProperties tenantProperties) {
		return new XrskAuthorizationHandler(XrskRedis, tenantProperties);
	}

	@Bean
	public PasswordHandler passwordHandler() {
		return new XrskPasswordHandler();
	}

	@Bean
	public TokenHandler tokenHandler(JwtProperties jwtProperties) {
		return new XrskTokenHandler(jwtProperties);
	}

	@Bean
	public OAuth2ClientService oAuth2ClientService(JdbcTemplate jdbcTemplate) {
		return new XrskClientDetailService(jdbcTemplate);
	}

	@Bean
	public OAuth2UserService oAuth2UserService(IUserService userService) {
		return new XrskUserDetailService(userService);
	}

}
